<template>
  <div>
    <org-info-item :content="enterpriseInfo.pic ? enterpriseInfo.pic : ''" :title="'企业头像'" @itemData="itemData"></org-info-item>
    <org-info-item :content="enterpriseInfo.enterpriseName" :title="'企业名称'" @itemData="itemData"></org-info-item>
    <org-text-item :content="enterpriseInfo.remark" :title="'简介'" :is-empty="!enterpriseInfo.remark"
                   @itemData="itemData"></org-text-item>
    <org-info-item :content="enterpriseInfo.mobile" :title="'电话'" :is-empty="!enterpriseInfo.mobile"
                   @itemData="itemData"></org-info-item>


    <vant-over-lay-bind-mobile :show="show" :is-org="true" @cancelFun="cancelFun"></vant-over-lay-bind-mobile>
    <vant-over-lay-common :getData="sendShowCommonData" :show="showCommon"
                          @showFun="receiveCommonComStatus" @cancelFun="cancelFun"></vant-over-lay-common>
  </div>
</template>

<script>
  import OrgInfoItem from "./components/OrgInfoItem";
  import OrgTextItem from "./components/OrgTextItem";
  import VantOverLayBindMobile from '@/components/VantOverLayBindMobile'
  import VantOverLayCommon from '@/components/VantOverLayCommon'
  import {Toast} from 'vant'
  import store from "../../../repo/store/store";
  import TeamAPI from "../../../repo/api/TeamAPI";
  import {userTypes} from "../../../repo/store/user";

  export default {
    name: "index",
    components: {
      OrgInfoItem,
      OrgTextItem,
      VantOverLayBindMobile,
      VantOverLayCommon
    },
    data() {
      return {
        enterpriseInfo: {
          pic: 'http://192.168.2.28:50003/web-hft-ee/static/img/common_profile.png',
          enterpriseName: '中训联信息科技有限公司',
          mobile: '15645646456456',
          remark: '经营范围包括一般经营项目是：电子产品、通讯产品、计算机软硬件的技术开发与销售；网页设计；工艺美术设计；电脑动画设计；电脑图文设计；信息咨询；国内贸易；经营电子商务。（法律、行政法规、国务院决定禁止的项目除外，限制的项目须取得许可后方可经营），许可经营项目是：网页及视频的制作与培训。',
        },
        show: false,
        showCommon: false,
        sendShowCommonData: {},
        nameOrID: {
          title: '姓名,身份证',
          type: 'input',
          placeholder1: '请输入姓名',
          placeholder2: '请输入身份证号码'
        },
      }
    },
    watch: {
      show (n, o) {
        if (o != n && n === false) {
          this.fetchData()
        }
      },
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        TeamAPI.getTeamInfo().then((res) =>{
          if(res.responseData){
            this.enterpriseInfo = res.responseData.enterprise
          }
        }).catch(error => {
          console.log(error)
        })
      },
      itemData(data) {
        switch (data.title) {
          case '企业头像':

            break
          case '电话':
            this.show = true
            break
          case '企业名称':
            console.log('data', data)
            this.sendShowCommonData = {
              title: data.title,
              type: 'input_single',
              placeholder1: '请输入' + data.title
            }
            this.showCommon = true
            break
          case '简介':
            console.log('data', data)
            this.sendShowCommonData = {
              title: data.title,
              type: 'textarea',
              placeholder1: '请输入' + data.title
            }
            this.showCommon = true
            break
          default:
        }

      },
      receiveCommonComStatus(data, type) {
        if (data === '' || data === false) {
          return Toast('内容不能为空')
        }
        let sendData = {}

        sendData = type.title === '企业名称' ? {enterpriseName: data} : {remark: data}
        console.log('sendData', sendData)
        TeamAPI.modifyTeamInfo(sendData).then((result) => {
          Toast('修改成功')
          this.cancelFun()
          this.enterpriseInfo = result.responseData
        })
      },
      cancelFun() {
        this.showCommon = false
        this.show = false
      },
    }
  }
</script>

<style scoped>

</style>
